package com.mark.design.pattern.creational.prototype.clone;

import java.util.Date;

/**
 * Created by Choisaaaa on 2018/8/20.
 */
public class Pig implements Cloneable{
    private String name;
    private Date birthdate; //属性中含所有引用类型


    public Date getBirthdate() {
        return birthdate;
    }

    public void setBirthdate(Date birthdate) {
        this.birthdate = birthdate;
    }



    public Pig(String name, Date birthdate) {
        this.name = name;
        this.birthdate = birthdate;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        //在重写的克隆方法中实现深克隆
        Pig pig = (Pig) super.clone();
        pig.birthdate = (Date) pig.birthdate.clone();
        return pig;
    }

    @Override
    public String toString() {
        return "Pig{" +
                "name='" + name + '\'' +
                ", birthdate=" + birthdate +
                '}'+super.toString();
    }
}
